package com.itheima.exception;

import com.itheima.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author liuyp
 * @since 2025/5/10
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理Exception异常
     */
    @ExceptionHandler
    public Result handleException(Exception e){
        log.error("系统异常", e);
        return Result.error("系统正在维护，请稍后再试");
    }

    /**
     * 处理BusinessException异常：将异常信息返回给客户端
     */
    @ExceptionHandler
    public Result handleBusinessException(BusinessException e){
        log.error("业务异常", e);
        return Result.error(e.getMessage());
    }
}
